$(function (){
    let app = new Vue({
        el: "#app",
        data: {
            sysTitle: "固定资源管理系统",
            userID: "",
            userName: "",
            userImageSrc: "",
            userClass: "",
            userDepartment: "",
            backImageSrc: "images/common/back.jpg",
            subList1: [
                {href:"properties.html", li: " 资源管理"},
                {href:"departments.html", li: " 部门管理"},
                {href:"employees.html", li: " 员工管理"}
            ],
            subList2: [
                {href:"infos.html", li: " 个人信息"},
                {href:"passwords.html", li: " 密码修改"},
                {href:"util/login.html", li: " 注销"}
            ],
            departments: [{name: "资源部1", value: "1"},{name: "资源部2", value: "2"},{name: "资源部3", value: "3"},{name: "资源部4", value: "4"}],
            selectProperty: "",
            propertyImageSrc: "",
            imageShow: false,
            dataList: [{id: 10001, name: "电脑笔记本", info: "5.6寸、8g运行内存、512固态的高速惠普笔记本", price: 5000, image: "../images/common/back.jpg", eid: "李四", pid: "电子类产品", time: "2019-09-09", save: "笔记本电脑笔记本电脑记本电脑笔记本"},
                {id: 10002, name: "电脑笔记本", info: "5.6寸、8g运行内存、512固态的高速惠普笔记本", price: 5000,  image: "../images/common/back.jpg", eid: "李四", pid: "电子类产品", time: "2019-09-09", save: "笔记本电脑笔记本电脑记本电脑笔记本"},
                {id: 10003, name: "电脑笔记本", info: "5.6寸、8g运行内存、512固态的高速惠普笔记本", price: 5000,  image: "../images/common/back.jpg", eid: "李四", pid: "电子类产品", time: "2019-09-09", save: "笔记本电脑笔记本电脑记本电脑笔记本"},
                {id: 10004, name: "电脑笔记本", info: "5.6寸、8g运行内存、512固态的高速惠普笔记本", price: 5000,  image: "../images/common/back.jpg", eid: "李四", pid: "电子类产品", time: "2019-09-09", save: "笔记本电脑笔记本电脑记本电脑笔记本"},
                {id: 10005, name: "电脑笔记本", info: "5.6寸、8g运行内存、512固态的高速惠普笔记本", price: 5000,  image: "../images/common/back.jpg", eid: "李四", pid: "电子类产品", time: "2019-09-09", save: "笔记本电脑笔记本电脑记本电脑笔记本"},
                {id: 10006, name: "电脑笔记本", info: "5.6寸、8g运行内存、512固态的高速惠普笔记本", price: 5000,  image: "../images/common/back.jpg", eid: "李四", pid: "电子类产品", time: "2019-09-09", save: "笔记本电脑笔记本电脑记本电脑笔记本"},
                {id: 10006, name: "电脑笔记本", info: "5.6寸、8g运行内存、512固态的高速惠普笔记本", price: 5000,  image: "../images/common/back.jpg", eid: "李四", pid: "电子类产品", time: "2019-09-09", save: "笔记本电脑笔记本电脑记本电脑笔记本"},
                {id: 10006, name: "电脑笔记本", info: "5.6寸、8g运行内存、512固态的高速惠普笔记本", price: 5000,  image: "../images/common/back.jpg", eid: "李四", pid: "电子类产品", time: "2019-09-09", save: "笔记本电脑笔记本电脑记本电脑笔记本"},
                {id: 10006, name: "电脑笔记本", info: "5.6寸、8g运行内存、512固态的高速惠普笔记本", price: 5000,  image: "../images/common/back.jpg", eid: "李四", pid: "电子类产品", time: "2019-09-09", save: "笔记本电脑笔记本电脑记本电脑笔记本"}],//当前页要展示的列表数据
            dialogFormVisible: false,//添加表单是否可见
            dialogFormVisible4Edit:false,//编辑表单是否可见
            formData: {},//表单数据
            rules: {//校验规则
                info: [{ required: true, message: '资源规格为必填项', trigger: 'blur' }],
                pid: [{ required: true, message: '资源类型为必选项', trigger: 'blur' }],
                id: [{ required: true, message: '资源编号为必填项', trigger: 'blur' }],
                eid: [{ required: true, message: '资源类型为非必选项', trigger: 'blur' }],
                name: [{ required: true, message: '资源名称为必填项', trigger: 'blur' }],
                image: [{ required: true, message: '资源图片为必填项', trigger: 'blur' }],
                time: [{ required: true, message: '购入时间为必填项', trigger: 'blur' }],
                price: [{ required: true, message: '消费金额为必填项', trigger: 'blur' }],
                save: [{ required: true, message: '保存位置为必填项', trigger: 'blur' }],
            },
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:8,//每页显示的记录数
                total:0,//总记录数
                id: "",
                eName: "",

            }
        },
        created(){
            this.getIDAndName();
        },
        methods: {
            getIDAndName(){
                if(sessionStorage.getItem("userID") === null)
                {
                    location.href = "util/login.html";
                }else {
                    this.userID = sessionStorage.getItem("userID").toString();
                    this.userName = sessionStorage.getItem("userName").toString();
                    this.userImageSrc = "../" + sessionStorage.getItem("userImageSrc").toString()
                }
            },
            //分页查询
            getAll() {
                /* //组织参数，拼接url请求地址
                 // console.log(this.pagination.type);
                 param = "?tell="+this.pagination.tell;
                 param +="&name="+this.pagination.name;
                 param +="&time="+this.pagination.time;
                 //发送异步请求
                 axios.get("http://localhost:16/users/"+this.pagination.currentPage+"/"+this.pagination.pageSize+param).then((res)=>{
                     this.pagination.pageSize = res.data.data.size;
                     this.pagination.currentPage = res.data.data.current;
                     this.pagination.total = res.data.data.total;
                     this.dataList = res.data.data.records;
                 });*/
            },

            //切换页码
            handleCurrentChange(currentPage) {
                //修改页码值为当前选中的页码值
                this.pagination.currentPage = currentPage;
                //执行查询
                this.getAll();
            },

            //弹出添加窗口
            handleCreate() {
                this.dialogFormVisible = true;
                this.resetForm();
            },

            //重置表单
            resetForm() {
                this.formData = {};
            },

            //添加
            handleAdd () {
                /* axios.post("http://localhost:16/users", this.formData).then((res)=>{
                     if(res.data.flag){
                         //关闭弹窗
                         this.dialogFormVisible = false;
                         this.$message.success(res.data.msg);
                     }else
                         this.$message.error(res.data.msg);
                 }).finally(()=>{
                     //重新加载数据
                     this.getAll();
                 });*/
            },

            //取消
            cancel(){
                this.dialogFormVisible = false;
                this.dialogFormVisible4Edit = false;
                this.$message.info("操作已取消");
            },

            // 删除
            handleDelete(id, name) {
                   this.$confirm("是否要删除"+id+name+"用户的信息", "删除提示", {type:"info"}).then(()=>{
                       /*axios.delete("http://localhost:16/users/"+id).then((res)=>{

                           if(res.data.flag){
                               this.$message.success(res.data.msg);
                           }else
                               this.$message.error(res.data.msg);
                       }).finally(()=>{
                           //重新加载数据
                           this.getAll();
                       });*/
                   }).catch(()=>{
                       this.$message.info("取消操作");
                   });

            },

            //弹出编辑窗口
            handleUpdate(id) {
                /*axios.get("http://localhost:16/users/"+row.id).then((res)=>{
                    if(res.data.flag && res.data.data != null)
                    {*/
                alert(id);
                this.dialogFormVisible4Edit = true;

                /*       this.formData = res.data.data;
                   }else {
                       this.$message.error("数据同步失败，自动刷新");
                   }
               }).finally(()=>{
                   this.getAll();
               });*/
            },

            //修改
            handleEdit() {
                /*  axios.put("http://localhost:16/users", this.formData).then((res)=>{
                      if(res.data.flag)
                      {
                          this.dialogFormVisible4Edit = false;
                          this.$message.success(res.data.msg);
                      }else {
                          this.$message.error(res.data.msg);
                      }
                  }).finally(()=>{
                      this.getAll();
                  });*/
            },
        }
    });
    var left_nav = $(".left-nav");
    var left_lis = left_nav.children("li");
    var left_sub_nav = left_lis[0].children[1];
    $(left_sub_nav).children("li").eq(0).children("a").addClass("current");
   /* lis.addClass("current");*/
});